﻿using System.Web.Mvc;
using Autofac;
using Autofac.Integration.Mvc;
using System.Reflection;
using LOMBARDISPICK.Model.Infrastructure;
using LOMBARDISPICK.Model.Repositories;
using LOMBARDISPICK.Domain.Services;
namespace LOMBARDISPICK.Web
{
	public static class Bootstrapper
	{
		public static void Run()
		{
			SetAutofacContainer();
		}
		private static void SetAutofacContainer()
		{
			var builder = new ContainerBuilder();
			builder.RegisterControllers(Assembly.GetExecutingAssembly());
			builder.RegisterType<UnitOfWork>().As<IUnitOfWork>().InstancePerHttpRequest();
			builder.RegisterType<DatabaseFactory>().As<IDatabaseFactory>().InstancePerHttpRequest();
			builder.RegisterAssemblyTypes(typeof(TeamSeason_1985_2011Repository).Assembly)
			.Where(t => t.Name.EndsWith("Repository"))
			.AsImplementedInterfaces().InstancePerHttpRequest();
			builder.RegisterAssemblyTypes(typeof(TeamSeason_1985_2011Service).Assembly)
			.Where(t => t.Name.EndsWith("Service"))
			.AsImplementedInterfaces().InstancePerHttpRequest();
			var services = Assembly.Load("LOMBARDISPICK.Domain");
			builder.RegisterFilterProvider();
			IContainer container = builder.Build();
			DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
		}
	}
}
